package com.bcx.service;

import com.bcx.mapper.FsqsMapper;
import com.bcx.pojo.Fsqs;
import com.bcx.pojo.FsqsExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FsqsServiceImpl implements FsqsService {
    @Resource
    FsqsMapper fsqsMapper;
    @Override
    public PageInfo<Fsqs> selectAll(String title, Integer pageNum) {
        PageHelper.startPage(pageNum,2);
        List<Fsqs> fsqsList;
        FsqsExample fsqsExample=new FsqsExample();
        if (title!=null){
            FsqsExample.Criteria criteria=fsqsExample.createCriteria();
            criteria.andTitleLike(title);
            fsqsList=fsqsMapper.selectByExample(fsqsExample);
        }else {
            fsqsList=fsqsMapper.selectByExample(null);
        }
        PageInfo<Fsqs> pageInfo=new PageInfo<>(fsqsList);
        return pageInfo;
    }

    @Override
    public Integer insert(Fsqs fsqs) {
        return fsqsMapper.insert(fsqs);
    }

    @Override
    public Fsqs getById(Integer id) {
        return fsqsMapper.selectByPrimaryKey(id);
    }
}
